<?php
class Admini_Managestore1Controller extends Uuch_ManageController{
    
    public function init() {
        parent::init();
        $this->appendCss('/admins/css/adminshare.css');
        $this->appendCss('/admins/css/cangku.css');
        $this->appendScript('/admins/js/jquery/jquery-1.7.2.min.js');
        $this->view->countstore1 = Application_Model_StoreItem::countstore(1);        
        $this->view->countstore2 = Application_Model_StoreItem::countstore(2);
        $this->view->countstore3 = Application_Model_ingstore::getcountingstore();
        $this->view->countnotscan = Application_Model_StoreItem::countnotscan();
        $this->view->countbeyondnotscan = Application_Model_StoreItem::countnotscan("beyond");
        $this->view->countinstore = Application_Model_StoreItem::countinstore(1);        
        $this->view->countSpecialPackage = Application_Model_StoreItem::countSpecialPackage();
        $this->view->countProblem = Application_Model_StoreItem::countProblem();
        
        $this->view->type = 'store';
    }

   public function indexAction() {   
        $this->setTitle("仓库管理");
        $stype = '';
        $quick = $this->getSafeParam('quick');
        $pagesize = $this->getSafeParam('pagesize');
        $start = $this->getSafeParam('start'); 
        if(!$pagesize){ $pagesize=10; }
        if (!$start) {$start = 0;}
        $isdel = $this->getSafeParam("isdel"); 
        $stus='';       
        if($quick == ""){            
            $history = $this->getSafeParam('history');                                   
            $intype = $this->getSafeParam('intype');
            $timescope = $this->getSafeParam('timescope');
            $starttime = $this->getSafeParam('starttime');
            $endtime = $this->getSafeParam('endtime');
            $strart = date("m")%3==0?date("m")/3:((int)(date("m")/3)+1);        
            $shiptype = $this->getSafeParam('shiptype');
            $interior = $this->getSafeParam('interior');
            $startWeight = $this->getSafeParam('startWeight');
            $endWeight = $this->getSafeParam('endWeight');
            $startVolume = $this->getSafeParam('startVolume');
            $endVolume = $this->getSafeParam('endVolume');
            $day = $this->getSafeParam('day');
            $stus = $this->getSafeParam('stus');
            $nostore = $this->getSafeParam('nostore');
            $notscan = $this->getSafeParam('notscan');
            $special = $this->getSafeParam('special');
            $personal = Application_Model_User::getByStoreNo($quick)?Application_Model_User::getByStoreNo($quick):"";
            $problem = $this->getSafeParam("problem");
            
            if($personal){
                $this->view->personalCount = Application_Model_StoreItem::personalCount($personal->id);
                $this->view->personalInCount = Application_Model_StoreItem::personalInCount($personal->id);
            }
            if($timescope != null){
                switch ($timescope) {
                    case "yesterday":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
                        break;
                    case "day3":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                    case 'lastweek':
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1-7,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+7-7,date("Y")));
                        break;
                    case "week":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+7,date("Y")));
                        break;
                    case "month":
                        $starttime =  date("Y-m-d",mktime(0,0,0,date("m"),1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("t"),date("Y")));
                        break;
                    case "lastmonth":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m")-1,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m")-1,cal_days_in_month(CAL_GREGORIAN, date("m")-1, date("Y")),date("Y")));
                        break;
                    case "quarter":
                        $starttime = date("Y-m-d",mktime(0,0,0,($strart-1)*3+1,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,$strart*3,cal_days_in_month(CAL_GREGORIAN, $strart*3, date("Y")),date("Y")));
                        break;
                    case "lastquarter":
                        $starttime = date("Y-m-d",mktime(0,0,0,($strart-1)*3-2,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,($strart-1)*3,cal_days_in_month(CAL_GREGORIAN, ($strart-1)*3, date("Y")),date("Y")));
                        break;
                    case "year":
                        $starttime = date("Y-m-d",mktime(0,0,0,1,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,12,cal_days_in_month(CAL_GREGORIAN, 12, date("Y")),date("Y")));
                        break;
                    case "lastyear":
                        $starttime = date("Y-m-d",mktime(0,0,0,1,1,date("Y")-1));
                        $endtime = date("Y-m-d",mktime(0,0,0,12,cal_days_in_month(CAL_GREGORIAN, 12, date("Y")-1),date("Y")-1));
                        break;
                    case "day7":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-6,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                    case "day30":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-30,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                    default :
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-90,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                }
            }else{
                if($starttime == null && $endtime == ""){
                    $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")-1));
                    $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                }
            }
            if($nostore){
                $quick = trim($nostore);
    //          $storeno = trim($nostore);
                $interior = Application_Model_StoreItem::Interior_InStored;
            }        
            if($stus != ''){
                if($stus == 1){
                    if($day == 1){
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                    }
                    $stype = 6;
                }else if($stus == 2){
                    if($day == 1){
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                    }
                    $stype = 7;
                }else if($stus == 0){
                    $interior = '';
                }else{
                    $interior = $this->getSafeParam('interior');
                }
            }                        
            if($special == "special"){
                $stype = 17;
            }
            if($problem == 1){
                $stype = 77;
            }
            $words = array();
            for($i=0;$i<26;$i++){
                $words[]= chr(65+$i);
            }
            if($notscan == "notscan"){
                $stype = 3;
            }else if($notscan == "beyondnotscan"){
                $stype = 100;
            }
            $this->view->words = $words?$words:"";            
            $this->view->starttime = $starttime;
            $this->view->endtime = $endtime;
            $this->view->shiptype = $shiptype;
            $this->view->interior = $interior;
            $this->view->intype = $intype;
            $this->view->pagesize = $pagesize;
            $this->view->startWeight = $startWeight;
            $this->view->endWeight = $endWeight;
            $this->view->startVolume = $startVolume;
            $this->view->endVolume = $endVolume;
            $this->view->notscan = $notscan;
            $this->view->timescope = $timescope;
            $this->view->personal = $personal;
            $this->view->special = $special;            
            $this->view->history = $history;
            
            $this->view->stus = $stus;
            $this->view->problem = $problem;
            if($history == "1"){
                $stype = 5;
            }else if($history == "2"){
                $stype = 4;
            }
        }
        $storeItemSearch = new Application_Model_Filter_StoreItemSearch();
        $storeItemSearch->quick = $quick?$quick:"";
        $storeItemSearch->isdel = $isdel?$isdel:"";
        if($quick == ""){
            $storeItemSearch->dateinbegin = $starttime?$starttime:"";
            $storeItemSearch->dateinend = $endtime?$endtime:"";
            $storeItemSearch->stus = $stus?$stus:"";
            $storeItemSearch->interior = $interior?$interior:"";
            $storeItemSearch->day = $day?$day:"";            
            $storeItemSearch->notscan = $notscan?$notscan:"";
            $storeItemSearch->intype = $intype?$intype:"";
            $storeItemSearch->startWeight = $startWeight?$startWeight:"";
            $storeItemSearch->endWeight = $endWeight?$endWeight:"";
            $storeItemSearch->startVolume = $startVolume?$startVolume:"";
            $storeItemSearch->endVolume = $endVolume?$endVolume:"";
            $storeItemSearch->shiptype = $shiptype?$shiptype:"";
            $storeItemSearch->special = $special?$special:"";
            $storeItemSearch->history = $history?$history:"";
            $storeItemSearch->problem = $problem?$problem:"";
        }
        if($isdel == 1){
            $stype = 8;
        }
        $this->view->isdel = $isdel;
        $this->view->quick = $quick;
        $this->view->StoreItem = Application_Model_StoreItem::getMyByFilter($storeItemSearch,$pagesize,$start);
        
        $this->view->StoreItemList = $this->view->StoreItem['list']; 
        $list=$this->view->StoreItem['list'];
        $time = date('Y-m-d', strtotime('- ' . 6 . ' month'));
        if(count($list)<2){
            foreach($list as $item){
                if($item->locationNo=='GZ-11' || $item->locationNo=='BH-11' ||  $item->locationNo=='TS-11' || $item->locationNo=='GQ-11' && ($item->isdelete==0)){
                    $stype = 17;
                }elseif($item->createdate>=date('Y-m-d',time())&&$item->isdelete==0){
                    $stype = 6;
                }elseif($item->state==1 && ($item->isdelete==1 ||$item->dateInStore<$time)){
                    $stype = 8;
                }elseif($item->state==2 && $item->interior==10){
                    $stype = 5;
                }elseif($item->isProblem==1 && $item->isdelete==0){
                    $stype = 77;
                }elseif($item->isdelete!=1){
                    $stype = 4;
                }
            }
        }
       if($stus!=''){
           if($stus == 2){
                if($day == 1){
                    $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                    $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                }
                $stype = 7;
            }
        }
        $this->view->interiorNames = Application_Model_StoreItem::getInteriorNames();
        $this->view->stype = $stype;        
    }


    /**
     * 预报入库管理
     */
    public function ingstoreAction() {
        $count = 15;
        $start = $this->getSafeParam('start');
        $this->setTitle("预报入库管理");
        //查询条件
        $username = $this->getSafeParam('username');
        $state = $this->getSafeParam('state');
        $orderno = $this->getSafeParam('orderno');
        $storeno = $this->getSafeParam('storeno');
        $dateinbegin = $this->getSafeParam('dateinbegin');
        $dateinend = $this->getSafeParam('dateinend');
        $day = $this->getSafeParam('day');
        if (!$start) {
            $start = 0;
        }
        $stype = 9;
        if($day == 1){
            $stype = 10;
        }
        $this->view->username = $username;
        $this->view->orderno = $orderno;
        $this->view->state = $state;
        $this->view->dateinbegin = $dateinbegin;
        $this->view->dateinend = $dateinend;
        $this->view->storeno = $storeno;
        $this->view->IngstoreItem = Application_Model_ingstore::getMyByFilter($username,  $storeno, $orderno, $dateinbegin, $dateinend,$state,$day,$count, $start);
        $this->view->IngstoreItemList = $this->view->IngstoreItem['list'];
        $this->view->type = 'store';
        $this->view->stype = $stype;
    }

    private function AnalysisOrder($storeId)
    {
        $order = Application_Model_Order::load($storeId);
        $ingstore=Application_Model_ingstore::load($storeId);
        if($ingstore){
            return true;
        }
        if(!$order){
            return true;
        }
        if($order->scheme > 0 && $order->rechangeStatus != Application_Model_Order::ReChange_Complete){
            return true;
        }
        if($order->status == Application_Model_Order::STATUS_SELLER_SENDED || $order->status == Application_Model_Order::STATUS_SUBSCRIBE 
                || $order->status == Application_Model_Order::STATUS_OUTTIME_INSTORE || $order->status == Application_Model_Order::STATUS_OUTTIME_FIN){
            return true;
        }
        return false;
    }
    private function AnalysisOrderIng($item,$storeno,$logistics,$logisticsName)
    {
        $operator = Uuch_Util::getUserNikeName();
        $firstWord = substr($storeno,0,1);
        $shipItem = Application_Model_shipType::getByName($logisticsName);
        $shipId = 181;//其他
        if($shipItem){
            $shipId = $shipItem->Id;
        }
        $orderItem = Application_Model_Order::getByShipNo($logistics);
        if(!$orderItem){
            $trackItem = Application_Model_Tracking::getOneByObjectTypeOperateTypeContent(Application_Model_DomainobjectType::ObjectType_Order, Application_Model_Tracking::Type_ReissueLogistics,$logistics);
            if($trackItem){
                $orderItem = Application_Model_Order::load($trackItem->ObjectId);
                $item->productName = "代购订单".$orderItem->OrderNum."物品部分入库";
                $item->save();
                $orderItem->rechangeStatus = Application_Model_Order::ReChange_Complete;
//                $orderItem->scheme = Application_Model_Order::Scheme_Succeed;
                $orderItem->save();
            }
        }
        if ($orderItem) {
            $orderItem->status = Application_Model_Order::STATUS_INSTORE;
            $orderItem->dateInStore = date('Y-m-d H:i:s');
            $orderItem->dateConfrim = date("Y-m-d H:i:s");
            $orderItem->ActivityConsumeExchangeScore();
            $orderItem->save();
            $isCk = false;
            foreach ($orderItem->getItems() as $val) {
                if($val->CkPass == Application_Model_DomainobjectType::CK_Problem){
                    $isCk = true;
                }
            }
            if($orderItem->CkPass == Application_Model_DomainobjectType::CK_Problem){
                $isCk = true;
            }
            if($isCk){
                $item->productName = "代购订单".$orderItem->OrderNum."物品部分入库";
                $item->IsProblem = Application_Model_DomainobjectType::CK_Problem;
                $item->save();
//                Application_Model_Mail::addMail( "您收到一个质检异常的包裹",1,$item->userid,"您的代购订单".$orderItem->OrderNum."入库出现质检异常，<a href='/member/orderdetail/id/".$orderItem->Id."' target='_block'>点击查看详情！</a>");
            }
        }
        if ($firstWord == 'D'){
            $storeId = substr($storeno,1);
            $order = Application_Model_Order::load($storeId);
            $trackItem = true;
            if($order->scheme == Application_Model_Order::Scheme_Change || $order->scheme == Application_Model_Order::Scheme_Reissue){
                $trackItem = Application_Model_Tracking::getOneByObjectTypeOperateTypeContent(Application_Model_DomainobjectType::ObjectType_Order, Application_Model_Tracking::Type_ReissueLogistics,$logistics);
                if(!$trackItem){
                    Application_Model_Tracking::addTrack(Application_Model_DomainobjectType::ObjectType_Order, $storeId, $operator, $logistics, Application_Model_Tracking::User_None, Application_Model_Tracking::Type_ReissueLogistics, date("Y-m-d H:i:s"),$shipId);
                }
                $trackItem = false;
                $orderItem->rechangeStatus = Application_Model_Order::ReChange_Complete;
                $orderItem->save();
            }
            if($trackItem == true){
                $order->logistics = $shipId;
                $order->logisticsNo = $logistics;
            }
            $order->dateInStore = date('Y-m-d H:i:s');
            $order->dateConfrim = date("Y-m-d H:i:s");
            $order->status = Application_Model_Order::STATUS_INSTORE;
            $order->ActivityConsumeExchangeScore();
            $order->save();
            $isCk = false;
            foreach ($order->getItems() as $val) {
                if($val->CkPass == Application_Model_DomainobjectType::CK_Problem){
                    $isCk = true;
                }
            }
            if($order->CkPass == Application_Model_DomainobjectType::CK_Problem){
                $isCk = true;
            }
            if($isCk){
                $item->productName = "代购订单".$orderItem->OrderNum."物品部分入库";
                $item->IsProblem = Application_Model_DomainobjectType::CK_Problem;
                $item->save();
//                Application_Model_Mail::addMail( "您收到一个质检异常的包裹",1,$item->userid,"您的代购订单".$orderItem->OrderNum."入库出现质检异常，<a href='/member/orderdetail/id/".$orderItem->Id."' target='_block'>点击查看详情！</a>");
            }
        }
        //预报包裹
        $ingstoreItem = Application_Model_ingstore::getByShipNo($logistics);
        if ($ingstoreItem) {
            $ingstoreItem->state = '1';
            $ingstoreItem->save();
            if($ingstoreItem->CkPass == Application_Model_DomainobjectType::CK_Problem){
                $item->IsProblem = Application_Model_DomainobjectType::CK_Problem;
                $item->save();
//                Application_Model_Mail::addMail( "您收到一个质检异常的包裹",1,$item->userid,"您的预报包裹入库出现质检异常，<a href='/member/forecastdetail?id=".$ingstoreItem->Id."' target='_block'>点击查看详情！</a>");
            }
        }
        //换货包裹
        $returnGoods = Application_Model_ReturnGoods::getByLogistics($logistics);
        if($returnGoods) {
            $returnGoods->status = Application_Model_ReturnGoods::STATUS_Receipt;
            $returnGoods->save();
            $returnGoods->addBillLog(Application_Model_ReturnGoods::STATUS_Receipt);
            Application_Model_Operate::addOperate(0, null, $returnGoods->productName, "退换货仓库已录单", $returnGoods->UserId);
            if($returnGoods->CkPass == Application_Model_DomainobjectType::CK_Problem){
                $item->IsProblem = Application_Model_DomainobjectType::CK_Problem;
                $item->save();
//                Application_Model_Email::sendMail($item->userid, $item->userinfo->email, "您收到一个质检异常的包裹", "您的预报包裹入库出现质检异常，<a href='/member/forecastdetail?id=".$ingstoreItem->Id."' target='_block'>点击查看详情！</a>");
            }
        }
        //上门取件
        if(preg_match('/^\d+$/', $storeno)){
            $no = strrev($storeno);
            $visiting = Application_Model_VisitingServer::load('1'.$no);
            if($visiting){
                $visiting->VisitingInStore($item->logistics);
            }
        }
        if($item->intype == "上门取件") {
            $visitingItem = Application_Model_VisitingServer::getByShipNo($logistics);
            if($visitingItem) {
                $visitingItem->VisitingInStore($item->logistics);
            }
        }
        if($item->IsProblem == Application_Model_DomainobjectType::CK_Problem){
            Application_Model_Operate::addOperate(0, null, $item->barcode, "标注入单包裹为异常包裹", $item->userid);
        }
        return true;
    }

    /**
     * 包裹入库
     */
    public function  instoreAction() {
        $this->setTitle("包裹入库");
        $this->appendScript('/js/jquery.validate.min.js')->appendScript('/js/messages_cn.js');

        $this->view->type = 'store';
        $this->view->stype = 1;
        $this->view->storeArrName = Application_Model_StoreItem::getNames();
        if ($this->getRequest()->isPost()) {
            $logistics = $this->getSafeParam('logistics');
            $logisticsName = $this->getSafeParam('logisticName');
            $storeno = $this->getSafeParam("storeno");
            $storeId = $this->getSafeParam('storeId');
            if(!$this->AnalysisOrder($storeId)){
                if(!$this->getSafeParam('issplitbox')){
                    $this->message("该代购订单的状态错误，无法入库。请跟上面代购人员沟通！");
                    return;
                }
            }
            $barcode = Application_Model_StoreItem::createBarCode();
            $itemType = "";
            if(is_array($this->_getParam('itemType'))){
                foreach ($this->_getParam('itemType') as $type){
                    $itemType = $itemType | intval($type);
                }
            }else{
                $itemType = $this->_getParam('itemType');
            }
            $itemType = ($itemType=="" || $itemType == NULL)?0:$itemType;
            $item = new Application_Model_StoreItem();

            $item->productName = $this->getSafeParam('productName');
            $item->storeId = $storeId;
            $item->dateInStore = $this->now();
			$item->dateOver = date('Y-m-d H:i:s', strtotime('+6 month'));
            $item->quantity = 1;
            $item->state = Application_Model_StoreItem::STATUS_InStored;
            $item->logisticsName = $logisticsName;
            $item->logistics = $logistics;
            $item->orderNo = $item->Logistics;
            $item->userid = $this->getSafeParam('userid');
            $item->weight = $this->getSafeParam('weight')*1000;
            $item->length = $this->getSafeParam('length');
            $item->width = $this->getSafeParam('width');
            $item->height = $this->getSafeParam('height');
            $item->createdate = $this->now();
            $item->isPack = $this->getSafeParam('isPack');
            $item->cnShipFee = $this->getSafeParam('cnShipFee');
            $item->bignessType = $this->getSafeParam('bignessType');
            $volumeWeight = $this->getSafeParam('volumeWeight')?$this->getSafeParam('volumeWeight')*1000:$item->weight;
            $item->volumeWeight = $volumeWeight;
            $item->CanVacuum = $this->getSafeParam('canVacuum');
            $item->isEmbargo = $this->getSafeParam('isEmbargo');
            $item->embargoReason = $this->getSafeParam("embargoReason");
            $item->barcode = $barcode;
            $item->Image = $this->getSafeParam('image');
            $item->Image = str_replace("http://old.uuch.com", "", $item->Image);
			$item->Image = str_replace("http://www.uuch.com", "", $item->Image);
            $item->itemType = $itemType;
            $item->remark = $this->getSafeParam('remark');
            $item->intype = $this->getSafeParam('intype');
            $item->operateName = Uuch_Util::getUserNikeName();
            $item->interior = Application_Model_StoreItem::Interior_HoldItem;
            $item->isdelete = 0;
            $item->IsProblem = 0;
            $itemCount = Application_Model_StoreItem::getCountByUserId($item->Userid);
            if($itemCount == 0){
                $accountItem = Application_Model_UserAccount::addAccount($item->Userid);
                $accountItem->TaskExchangeScore(Application_Model_Task::TASK_INSTORE);
            }
            try{
                $Kinfo = Application_Model_User::getByStoreno($storeno);
                if(preg_match("/^[0-9a-zA-Z]+@(([0-9a-zA-Z]+)[.])+[a-z]{2,4}$/i",$Kinfo->email)){
                    $receive = array('email' => $Kinfo->email, 'name' => $Kinfo->email);
                    $link = 'http://www.uuch.com/storehouse/personal/';
                    $name = $Kinfo->nikename;
                    $this->sendUserRkMail($receive, $link, $name, $logistics);
                }
                $item->save();
                $item->addImg($item->Image,  Application_Model_StoreImg::Status_Succeed);
            }catch(Exception $e){
                $this->message("同一时间有别的商品入库，造成仓库条码冲突，请重新入库！");
                return;
            }
//            for($i=1;$i<6;$i++){
//                $img = $this->getSafeParam("imgurl$i");
//                if($img != ""){
//                    $item->addImg($img);
//                }
//            }
            Application_Model_Operate::addOperate(0, null, $item->barcode, "包裹录单", $item->userid);
            $this->AnalysisOrderIng($item,$storeno, $logistics, $logisticsName);
            $this->redirect("warehousing", "managestore", array('id'=>$item->id));
        }
        
       
    }
    
/**
     * 入库邮件提醒
     */
    public function sendUserRkMail($receive, $link, $name, $bill) {
        $title = "包裹入库通知";
        $body = "尊敬的悠奇用户：" . $name . "您好！
                    
                感谢您选择悠奇网的服务

                您的国内包裹（" . $bill . "）已由快悌公司派送至悠奇公司，我们已对您的包裹拍照、称重并已上传信息至您的

                个人云仓库，如您需要查看包裹信息及状态请点击下面的链接查看。

                $link

                如果您点击此链接后发现它可能已损坏，请复制此链接并将其粘贴到新的浏览器窗口中。

                感谢您使用 uuch！

                uuch悠奇网敬上

                请不要回复此邮件。如果您要与UUCH小组联系，请登录您的帐户，点击任何页面顶部的“帮助”，然后点击“帮助中心”底部的“与我们联系”。
                ";

        return Uuch_Mail::SendMail($title, $body, $receive);
    }


    public function barcodeinfoAction()
    {
        $barcode = $this->getSafeParam("barcode");
        $storeItem = Application_Model_StoreItem::surebybarcode($barcode);
        if(!$storeItem) {
            $this->json(array("status"=>0));
            return ;
        }
        $userItem = Application_Model_User::load($storeItem->Userid);
        if(!$userItem) {
            $this->json(array("status"=>0));
            return ;
        }
        $userArr["storeId"] = $storeItem->Id;
        $userArr["nikename"] = $userItem->Nikename;
        $userArr["email"] = $userItem->Email;
        $userArr["storeno"] = $userItem->Storeno;
        $userArr["storeLocation"] = $userItem->byStoreLocation();
        $this->json(array("status"=>1,"userArr"=>$userArr));
    }
    
    public function updateweightAction()
    {
        $barcode = $this->getSafeParam("barcode");
        $weight = $this->getSafeParam("weight");
        if($weight == ""){
            $this->json(array("status"=>0));
            return ;
        }
        $length = $this->getSafeParam('length')?$this->getSafeParam('length'):0;
        $width = $this->getSafeParam('width')?$this->getSafeParam('width'):0;
        $height = $this->getSafeParam('height')?$this->getSafeParam('height'):0;
        $volume = ($length*$width*$height)/5000;
        $volumeWeight = $this->getSafeParam('volumeWeight');
        $volumeWeight = $volumeWeight?$volumeWeight:($volume==0?$weight:$volume);
        $storeItem = Application_Model_StoreItem::surebybarcode($barcode);
        if(!$storeItem) {
            $this->json(array("status"=>0));
            return ;
        }
        $storeItem->weight = $weight*1000;
        $storeItem->length = $length;
        $storeItem->width = $width;
        $storeItem->height = $height;
        $storeItem->volumeWeight = $volumeWeight*1000;
        $storeItem->save();
        $this->json(array("status"=>1));
        return ;
    }
    
    public function shiptypeAction(){
        $words = array();
        for($i=0;$i<26;$i++){
            $name = chr(65+$i);
            $shipItem = Application_Model_shipType::getByWord($name);
            foreach ($shipItem as $shipVal) {
                $words[$name][] = $shipVal->Name;
            }
        }
        $this->json(array("ship"=>$words));
    }


    public function warehousingAction(){
        $this->setTitle("条码打印");
        $result = Application_Model_StoreItem::load($this->getSafeParam('id'));
        $location = Application_Model_StoreLocation::getLocation($result->userid);        
        $num = 0;
        if(Application_Model_StoreItem::openNewLocation($result->userid)){
            $opt = Application_Model_User::load($result->userid);
            $time = date("Y-m-d" , time());
            $opt->locationtime = $time;
            $opt->save();
            $num = 1;
        }
        $this->view->num = $num;
        $this->view->result = $result;
        $this->view->location = $location;
    }

    /**
     * 根据仓库号，获取用户信息
     * @return type
     */
    public function userinfoAction() {
        $storeNo = $this->getSafeParam('storeno');
        $firstWord = substr($storeNo,0,1);
        $user = NULL;
        $type = Application_Model_StoreItem::SOURCE_SELF;
        $addtion = array();
        $storeid = null;
        $arrOrder = array();
        if($firstWord =='F'){//代购订单
            //$storeNo = 'P'.substr($storeNo, 1);
            //$type = Application_Model_StoreItem::SOURCE_AGENT_BUY;
        } else if ($firstWord =='D'){
            $type = Application_Model_StoreItem::SOURCE_AGENT_BUY;
            $storeId = substr($storeNo,1);
            $order = Application_Model_Order::load($storeId);
            if(!$order){
                $this->json(0);
                return ;
            }
            $user = Application_Model_User::load($order->UserId);
            // $orderPath = Application_Model_PathLevel::bySubId($storeId);
            // if($orderPath){
            //     $path = explode("/", $orderPath->Path);
            //     $subItem = Application_Model_PathLevel::byPath($path[0]);
            //     $arrOrder = $this->getOrderSubInfo($subItem,$storeId);
            // } else {
                $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($storeId,Application_Model_DomainobjectType::ObjectType_Order);
                $arrOrder[$storeId]["parentId"] = $order->Id; //代购父级Id
                $arrOrder[$storeId]["storeid"] = $order->OrderNum; //代购单号
                $arrOrder[$storeId]["status"] = $order->Status;
                $arrOrder[$storeId]["statusName"] = $order->StatusName;
                $arrOrder[$storeId]["problemContent"] = $order->problemContent; //问题原因
                $arrOrder[$storeId]["dateCreated"] = $order->datePaid; //代购付款时间
                $arrOrder[$storeId]["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
                $arrOrder[$storeId]["orderdetail"] = $this->getOrderInfo($order); //物品详情
                $arrOrder[$storeId]["arrProblem"] = $this->getOrderProblemInfo($order->Id); //物品问题详情
            // }
        } else if(preg_match('/^\d+$/', $storeNo)){//上门取件
             $no = strrev($storeNo);
             $visiting = Application_Model_VisitingServer::load('1'.$no);
             if($visiting){
                $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($visiting->Id,Application_Model_DomainobjectType::ObjectType_Visiting);
                $addtion["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
                $user = Application_Model_User::load($visiting->UserId);
                $type = Application_Model_StoreItem::SOURCE_VISITING;
                $storeid = $visiting->Id;
                $addtion['vistingId'] = $visiting->Id;
                $addtion['name']= $visiting->WaresName;
                $addtion['description'] = $visiting->WaresDescribe;
                $addtion["isInStore"] = $visiting->interior>=  Application_Model_VisitingServer::Interior_InStore?true:false;
                $addtion["expressName"] = $visiting->Express->Name;
                if($visiting->IsWay ==1 and $visiting->WayId != ""){
                    $type = Application_Model_StoreItem::SOURCE_VISITINGWAY;
                    $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($visiting->Id,Application_Model_DomainobjectType::ObjectType_VisitingWay);
                    $addtion["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
                }
             }
        }
        
        if(!$user){
            $user = Application_Model_User::getByStoreNo($storeNo);
        }

        if ($user == null) {
            $this->json(0);
            return;
        }
        $storeLocation = $user->byStoreLocation();
        $countstore = Application_Model_StoreItem::coustore($user->id);
        $this->json(array('userid' => $user->Id,'type'=>$type, 'email' => $user->Email, 'nikeName' => $user->Nikename,'countstore' =>$countstore,'dq' =>$user->byip,'storeLocation'=>$storeLocation,"userRemark"=>$user->remark,'addtion'=>$addtion,
            "storeid"=>$storeid,"arrOrder"=>$arrOrder));
    }
    private function getOrderSubInfo($subItem,$storeId)
    {
        $arrOrder = array();
        $i = 1;
        foreach ($subItem as $subVal) {
            $parentOrderItem = Application_Model_Order::load($subVal->parentId);
            $order = Application_Model_Order::load($subVal->SubId);
            if($order->Isdelete == 1){
                continue;
            }
            if(array_key_exists($subVal->SubId,$arrOrder)){
                continue;
            }
            $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($subVal->SubId,Application_Model_DomainobjectType::ObjectType_Order);
            $arrOrder[$order->Id]["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
            $arrOrder[$order->Id]["isSel"] = 0; //选择入库的代购
            if($storeId == $order->Id){
                $arrOrder[$order->Id]["isSel"] = 1;
            }
            $arrOrder[$order->Id]["parentId"] = $subVal->parentId; //代购父级Id
            $arrOrder[$order->Id]["storeid"] = $parentOrderItem->OrderNum."($i)"; //代购单号
            $arrOrder[$order->Id]["status"] = $order->Status;
            $arrOrder[$order->Id]["statusName"] = $order->StatusName;
            $arrOrder[$order->Id]["problemContent"] = $order->problemContent; //问题原因
            $arrOrder[$order->Id]["dateCreated"] = $order->datePaid; //代购付款时间
            $arrOrder[$order->Id]["orderdetail"] = $this->getOrderInfo($order); //物品详情
            $arrOrder[$order->Id]["arrProblem"] = $this->getOrderProblemInfo($order->Id); //物品问题详情
//            $arrOrder[$order->Id]["isUnbind"] = $this->getItemIsUnbind($order);
            $i++;
        }
        return $arrOrder;
    }
    private function getOrderInfo($order)
    {
        ini_set('memory_limit', '512M');
        $orderdetail = array();
        $orderItem = $order->shipdetail;
        foreach ($orderItem as $key1 => $ordervalue) {
            $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($ordervalue->Id,Application_Model_DomainobjectType::ObjectType_OrderItem);
            $orderdetail[$key1]["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
            $orderdetail[$key1]["id"] = $ordervalue->id; //商品id
            $orderdetail[$key1]["productName"] = $ordervalue->productName;//商品名称
            $orderdetail[$key1]["price"] = $ordervalue->price; //商品单价
            $orderdetail[$key1]["quantity"] = $ordervalue->quantity; //商品数量
            $orderdetail[$key1]["status"] = $ordervalue->status; //商品状态
            $orderdetail[$key1]["comment"] = $ordervalue->comment; //商品备注
            $orderdetail[$key1]["description"] = $ordervalue->description; //悠奇备注
            $orderdetail[$key1]["problemContent"] = $ordervalue->problemContent; //问题描述
            $orderdetail[$key1]["ckPass"] = $ordervalue->CkPass; //物品状态
            $productd = $ordervalue->byproductd;
            $orderdetail[$key1]["url"] = $productd->url; //淘宝地址
            $orderdetail[$key1]["tgurl"] = $ordervalue->taoBaoUrl; //推广地址
            $orderdetail[$key1]["remoteImage"] = $productd->remoteImage; //图片地址
			//$orderdetail[$key1]["PropertyAlias"] = iconv_strlen($productd->PropertyAlias)>=50?mb_substr($productd->PropertyAlias,0,50, 'utf-8').'...':$productd->PropertyAlias; //商品款式
			$propertyAlias = Application_Model_Product::parsePropertyAlias($productd->PropertyAlias);
            $orderdetail[$key1]["PropertyAlias"] = iconv_strlen($propertyAlias)>=50?mb_substr($propertyAlias,0,50, 'utf-8').'...':$propertyAlias; //商品款式
        }
        return $orderdetail;
    }
    private function getItemIsUnbind($order)
    {
        $isUnbind = false;
        $error = 0;
        foreach ($order->getItems() as  $ordervalue) {
            if($ordervalue->status == Application_Model_Order::Abnormal_Error){
                $error = 1;
            }
        }
        if(count($order->getItems()) === $error){
            return true;
        }
        $orderQuality = Application_Model_QualityProblem::byObjectIdObjectType($order->Id,Application_Model_DomainobjectType::ObjectType_Order);
        if($orderQuality && $order->status == Application_Model_Order::Abnormal_Error){
            $isUnbind = true;
        }
        
        return $isUnbind;
    }
    private function getOrderProblemInfo($orderId)
    {
        $arrProblem = array();
        $problemItem = Application_Model_problem::byissue($orderId, Application_Model_problem::TYPE_ORDER);
        foreach ($problemItem as $key => $pbVal) {
            $arrProblem[$key]["issueetype"] = $pbVal->Issuetype;
            $arrProblem[$key]["content"] = htmlspecialchars($pbVal->Content);
            $arrProblem[$key]["dateCreated"] = $pbVal->DateCreated;
        }
        return $arrProblem;
    }

    public function showproblemAction()
    {
        $orderId = $this->getSafeParam("orderId");
        $problemContent = $this->getOrderProblemInfo($orderId);
        $this->json(array("status"=>1,"problemContent"=>$problemContent));
    }
    /**
     * 根据物流单号，获取包裹信息
     */
    public function logisticsinfoAction(){
        ini_set('memory_limit', '512M');
        $infoArr = array();
        $userInfo = array();
        $user = "";
        $logistics = $this->getSafeParam('shipNo');
        $infoArr["intype"] = "自助包裹";
        $isCheck = true;
        $visitingItem = Application_Model_VisitingServer::getByShipNo($logistics);
        if($visitingItem) {
            $infoArr["shipType"] = "顺丰";
            $infoArr["waresName"] = $visitingItem->waresName;
            $infoArr["waresDescribe"] = $visitingItem->waresDescribe;
            $infoArr["userid"] = $visitingItem->UserId;
            $infoArr["intype"] = "上门取件";
            $infoArr["storeid"] = $visitingItem->Id;
            $infoArr["problemNote"] = $visitingItem->problemNote;
            $infoArr["isInStore"] = $visitingItem->interior>=Application_Model_VisitingServer::Interior_InStore?true:false;
            $infoArr["expressName"] = $visitingItem->Express->Name;
            $user = Application_Model_User::load($visitingItem->UserId);
            $isCheck = false;
        }
        $returnGoodsItem = Application_Model_ReturnGoods::getByLogistics($logistics);
        if($isCheck && $returnGoodsItem){
            $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($returnGoodsItem->Id,Application_Model_DomainobjectType::ObjectType_Exchange);
            $infoArr["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
            $infoArr["shipType"] = $returnGoodsItem->ReLogisticsName;
            $infoArr["name"] = $returnGoodsItem->ProductName;
            $infoArr["returnReason"] = $returnGoodsItem->ReturnReason;
            $infoArr["userid"] = $returnGoodsItem->UserId;
            $infoArr["intype"] = $returnGoodsItem->SourceName;
            $infoArr["storeid"] = $returnGoodsItem->Id;
            $infoArr["problem"] = $returnGoodsItem->Problem;
            $infoArr["exception"] = $returnGoodsItem->exception;
            $user = Application_Model_User::load($returnGoodsItem->UserId);
            $isCheck = false;
        }
        $orderItem = Application_Model_Order::getByShipNo($logistics);
        if(!$orderItem){
            $trackItem = Application_Model_Tracking::getOneByObjectTypeOperateTypeContent(Application_Model_DomainobjectType::ObjectType_Order, Application_Model_Tracking::Type_ReissueLogistics,$logistics);
            if($trackItem){
                $infoArr["shipType"] = $trackItem->ShipItem->name;
                $orderItem = Application_Model_Order::load($trackItem->ObjectId);
            }
        } else {
            $infoArr["shipType"] = $orderItem->logname->name;
        }
        if($isCheck && $orderItem){
            $infoArr["intype"] = $orderItem->PayDescription;
            $orderPath = Application_Model_PathLevel::bySubId($orderItem->Id);
            $storeId = $orderItem->Id;
            // if($orderPath){
            //     $path = explode("/", $orderPath->Path);
            //     $subItem = Application_Model_PathLevel::byPath($path[0]);
            //     $infoArr["orderArr"] = $this->getOrderSubInfo($subItem,$storeId);
            // } else {
                $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($orderItem->Id,Application_Model_DomainobjectType::ObjectType_Order);
                $infoArr["orderArr"][$storeId]["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
                $infoArr["orderArr"][$storeId]["parentId"] = $storeId; //代购父级Id
                $infoArr["orderArr"][$storeId]["storeid"] = $orderItem->OrderNum; //代购单号
                $infoArr["orderArr"][$storeId]["status"] = $orderItem->Status;
                $infoArr["orderArr"][$storeId]["statusName"] = $orderItem->StatusName;
                $infoArr["orderArr"][$storeId]["dateCreated"] = $orderItem->datePaid; //代购付款时间
                $infoArr["orderArr"][$storeId]["orderdetail"] = $this->getOrderInfo($orderItem); //物品详情
                $infoArr["orderArr"][$storeId]["arrProblem"] = $this->getOrderProblemInfo($storeId); //物品问题详情
            // }
            $user = Application_Model_User::load($orderItem->UserId);
            $isCheck = false;
        }
        //预报入库
        $ingstore = Application_Model_ingstore::getByShipNo($logistics);
       //
        if($isCheck && $ingstore){
             $online= Application_Model_ingstoreproduct::getbyingstoreid($ingstore->id);
             
             $storeId =$ingstore->id;
            //判断是自助包裹还是网购包裹
            if($ingstore->type==2){
                $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($ingstore->Id,Application_Model_DomainobjectType::ObjectType_Online);
                $infoArr["orderArr"][$storeId]["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
                $infoArr["shipType"] = $ingstore->shipType;
                $infoArr["intype"] = $ingstore->PayOnline;
                $infoArr["orderArr"][$storeId]["name"] = $ingstore->name;
                $infoArr["orderArr"][$storeId]["storeid"] = $ingstore->instore_no;
                $infoArr["orderArr"][$storeId]["dateCreated"] = $ingstore->createtime;
                $infoArr["orderArr"][$storeId]["orderdetail"] = $this->getOnlineInfo($ingstore);
                $infoArr["orderArr"][$storeId]["status"] = $ingstore->state;
                $infoArr["remark"] = $ingstore->remark;
                $infoArr["userid"] = $ingstore->userid;
                $infoArr["storeid"] = $ingstore->id;
                $user = Application_Model_User::getByUserId($ingstore->userid);
                $isCheck = false;
            }else{
                $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($ingstore->Id,Application_Model_DomainobjectType::ObjectType_Ing);
                $infoArr["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
                $infoArr["shipType"] = $ingstore->shipType;
                $infoArr["name"] = $ingstore->name;
                $infoArr["remark"] = $ingstore->remark;
                $infoArr["userid"] = $ingstore->userid;
                $infoArr["intype"] = $ingstore->PayDescription;
                $infoArr["storeid"] = $ingstore->id;
                $user = Application_Model_User::getByUserId($ingstore->userid);
                $isCheck = false;
            }
        }
        if($user){
            $userInfo["userId"] = $user->id;
            $userInfo["storeno"] = $user->storeno;
            $userInfo["email"] = $user->email;
            $userInfo["nikename"] = $user->nikename;
            $userInfo["userRemark"] = $user->remark;
            $userInfo["countstore"] = Application_Model_StoreItem::coustore($user->id);
//            $userInfo["dq"] = $user->CityName->name;
            $userInfo["storeLocation"] = $user->byStoreLocation();
        }
        $this->json(array("infoArr"=>$infoArr,"userInfo"=>$userInfo));
    }

     //网购包裹
     private function getOnlineInfo($insert)
    {

        ini_set('memory_limit', '512M');
        $orderdetail = array();
        $online= Application_Model_ingstoreproduct::getbyingstoreid($insert->id);
        foreach ($online as $key1 => $ordervalue) {
            $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($ordervalue->Id,Application_Model_DomainobjectType::ObjectType_Onlinesing);
            $orderdetail[$key1]["problemNum"] = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
            $orderdetail[$key1]["id"] = $ordervalue->id; //商品id
            $orderdetail[$key1]["productName"] = $ordervalue->productname;//商品名称
            $orderdetail[$key1]["price"] = $ordervalue->price; //商品单价
            $orderdetail[$key1]["quantity"] = $ordervalue->qty; //商品数量
            $orderdetail[$key1]["status"] = $ordervalue->state;; //商品状态
            $orderdetail[$key1]["comment"] = $ordervalue->remark; //商品备注
           // $orderdetail[$key1]["description"] ='fdf333';//$ordervalue->description; //悠奇备注
            //$orderdetail[$key1]["problemContent"] = '3333';//$ordervalue->problemContent; //问题描述
            //$orderdetail[$key1]["ckPass"] = 'fdfd3344';//$ordervalue->CkPass; //物品状态
            //$productd = $ordervalue->byproductd;
           // $orderdetail[$key1]["url"] = $ordervalue->url;//$ordervalue['url'];//$productd->url; //淘宝地址
            $orderdetail[$key1]["tgurl"] = $ordervalue->url; //推广地址
            $orderdetail[$key1]["remoteImage"] =$ordervalue->image;//$ordervalue['image']; //图片地址
            $orderdetail[$key1]["PropertyAlias"] = unserialize($ordervalue->attribute); //unserialize($ordervalue->attribute);//iconv_strlen($productd->PropertyAlias)>=50?mb_substr($productd->PropertyAlias,0,50, 'utf-8').'...':$productd->PropertyAlias; //商品款式
            //$propertyAlias = Application_Model_Product::parsePropertyAlias($productd->PropertyAlias);
            //$orderdetail[$key1]["PropertyAlias"] = iconv_strlen($propertyAlias)>=50?mb_substr($propertyAlias,0,50, 'utf-8').'...':$propertyAlias; //商品款式
        }
        return $orderdetail;
    }

    public function editAction()
    {
        $id = $this->getSafeParam('id');
        if($this->getSafeParam('operate') == 'editstore'){
             $store_set = array (
                'productName' => $this->getSafeParam('productName'),
                'Logistics' => $this->getSafeParam('Logistics'),
                'state' => $this->getSafeParam('state'),
                'wayId' => $this->getSafeParam('wayId'),
                'itemType' => $this->_getParam('itemType'),
                'dateInStore' => $this->getSafeParam('dateInStore'),
                'dateOut' => $this->getSafeParam('dateOut'),
                'weight' => $this->getSafeParam('weight'),
                'length' => $this->getSafeParam('length'),
                'width' => $this->getSafeParam('width'),
                'height' => $this->getSafeParam('height'),
                'volumeWeight' => $this->getSafeParam('volumeWeight'),
                'barcode' => $this->getSafeParam('barcode'),
                'remark' => $this->getSafeParam('remark'),
            );
           $storeItem  =  Application_Model_StoreItem::load($id);
           foreach ($store_set as $key => $v){
               $storeItem->$key = $v;
           }
           $storeItem->save();
           $this->view->message = 1; 
        }
        $ingstore = new Application_Model_StoreItem();
        $ingstoredetail = $ingstore->getingstoreDetail($id);

        $this->view->ingstoredetail = $ingstoredetail;
    }
    
    public function delstoreAction()
    {
        $idlist = $this->getSafeParam('idlist');
        $storeItem = new Application_Model_StoreItem();
        $result = $storeItem->delstore($idlist);
        echo 2;
        exit;
    }
    
    public function ingdetailAction()
    {
        $id = $this->getSafeParam('id');
        $this->view->ingdetail = Application_Model_ingstore::load($id);
        $this->view->productdetail=Application_Model_ingstoreproduct::getbyingstoreid($id);
    }
    
    public function storedetailAction()
    {        
        $this->setTitle("包裹详情");
        $id = $this->getSafeParam('id');
        $quickedit = $this->getSafeParam('quickedit')?$this->getSafeParam('quickedit'):"";
        if($this->getSafeParam('operate') == "editimg"){
            $id = $this->getSafeParam('storeid');
            $storeno = $this->getSafeParam('storeno');
            $user = Application_Model_User::getByStoreNo($storeno);
            //$userid = $this->getSafeParam("userid");
            $productName = $this->getSafeParam("productName");
            $weight = $this->getSafeParam("weight");
            $barcode = $this->getSafeParam("barcode");
            if($user->id == "" || $productName =="" || $weight =="" || $barcode == ""){
                $this->view->ma = 2;
            }else{
                $item = Application_Model_StoreItem::load($id);
                if($item){
                    $desc = "";
                    if($this->getSafeParam("status") != $item->state){
                        $desc = "状态由".$item->state."修改成".$this->getSafeParam("status");
                    }
                    if($item->weight != $weight*1000){
                        $desc .= "重量由".$item->weight."修改成".$weight*1000;
                    }
                    if($item->cnShipFee != $this->getSafeParam("cnShipFee")){
                        $desc .= "国内费用由".$item->cnShipFee."修改成".$this->getSafeParam("cnShipFee");
                    }
                    $item->userid = $user->id;
                    $item->barcode = $barcode;
                    $item->productName = $productName;
                    $item->weight = $weight*1000;
                    $item->state = $this->getSafeParam("status");
                    $item->cnShipFee = $this->getSafeParam("cnShipFee");
                    $item->logistics = $this->getSafeParam("logistics");
                    $item->logisticsName = $this->getSafeParam("Logisticsname");
                    $item->orderNo = $item->Logistics;
                    $item->bignessType = $this->getSafeParam("bignessType");
                    $itemType = "";
                    if(is_array($this->_getParam('itemType'))){
                        foreach ($this->_getParam('itemType') as $type){
                            $itemType = $itemType | intval($type);
                        }
                    }else{
                        $itemType = $this->_getParam('itemType');
                    }
                    $itemType = ($itemType=="" || $itemType == NULL)?0:$itemType;
                    $item->itemType = $itemType;
                    $item->length = $this->getSafeParam('length');
                    $item->width = $this->getSafeParam('width');
                    $item->height = $this->getSafeParam('height');
                    $volumeWeight = ($item->length==0||$item->width==0||$item->height==0)?$item->weight: $this->getSafeParam("volumeWeight")*1000;
                    $item->volumeWeight = $volumeWeight;
                    $item->canVacuum = $this->getSafeParam("canVacuum")=="on"?1:0;
                    $item->isEmbargo = $this->getSafeParam("isEmbargo")=="on"?1:0;
                    $item->isPack = $this->getSafeParam("isPack")=="on"?1:0;
                    $item->remark = $this->getSafeParam("remark");
                    if($this->getSafeParam('image') != "/pic/wu40.png"){
                        $item->Image = $this->getSafeParam('image');
                        $item->Image = str_replace("http://cdn.uuch.com", "", $item->Image);
                    }
                    $item->save();
                    Application_Model_Operate::addOperate(0, null, $item->barcode, "修改包裹信息".$desc, $item->userid);
                    $this->view->ma = 1;
                }else{
                    $this->view->ma = 3;
                }
            }
        }
        $storedetail = Application_Model_StoreItem::load($id);
        $location = Application_Model_StoreLocation::getLocation($storedetail->userid);
        $problemItem = Application_Model_ingstore::getByShipNo($storedetail->Logistics);
        $arrstatus = Application_Model_StoreItem::getStatusNames();
        $this->view->quickedit = $quickedit;
        $this->view->location = $location;
        $this->view->storedetail = $storedetail;
        $this->view->arrStatus = $arrstatus;
        if($problemItem){
            $this->view->problemContent = $problemItem->ProblemContent;
        }
    }
    
    public function launchAction()
    {
        $this->setTitle("发起国际运单");
        $idlist = $this->getSafeParam("id");
        $result = Application_Model_StoreItem::getstoreuser($idlist);
        if($result == 2 || $result == 4){
            $this->view->ma = $result;
        }else{
            $this->view->store = $result["storeItem"];
        }
        $operate = $this->getSafeParam("operate");
        if($operate == "addbill"){
            $isCompress = $this->getSafeParam("isCompress")=="on"?1:0;
            $isNoSkin = $this->getSafeParam("isNoSkin")=="on"?1:0;
            $isNoLogo = $this->getSafeParam("isNoLogo")=="on"?1:0;
            $bagWeight = Uuch_Util::getPackage($this->getSafeParam("productWeight"));
            $arrre = array(
                "billNo"  => $this->getSafeParam("billNo"),
                "shipMoney"  => $this->getSafeParam("shipMoney"),
                "consignee"  => $this->getSafeParam("consignee"),
                "state"  => $this->getSafeParam("state"),
                "conTel"  => $this->getSafeParam("conTel"),
                "conPostCode"  => $this->getSafeParam("conPostCode"),
                "conAdd"  => $this->getSafeParam("conAdd"),
                "expressId"  => $this->getSafeParam("expressId"),
                "shipType" => $this->getSafeParam("expressId"),
                "bagWeight"  => $bagWeight,
                "productWeight"  => $this->getSafeParam("productWeight"),
                "volumeWeight"  => $this->getSafeParam("volumeWeight"),
                "isCompress"  => $isCompress,
                "isNoSkin"  => $isNoSkin,                
                "isNoLogo"  => $isNoLogo,
                "userId"  => $this->getSafeParam("userid"),
                "remark"  => $this->getSafeParam("remark"),
            );
            $idlist = $this->getSafeParam("storeid");
            $billItem = Application_Model_wayBillItem::byaddbill($arrre,$idlist);
            $this->view->ma = $billItem;
        }
        $words = array();
        for($i=0;$i<26;$i++){
            $words[]= chr(65+$i);
        }
        $this->view->words = $words;
        $this->view->state = Application_Model_city::byAllcity();
        $this->view->shiptype = Application_Model_Express::getAll();
        $this->view->idlist = $idlist;
        $this->view->stype = 3;
    }
    public function selstoreAction()
    {
        $pagesize=5;        
        $pageindex = $this->getSafeParam('start');
        if(!$pageindex){$pageindex=0;}
        $id = $this->getSafeParam('id');
        $userid = $this->getSafeParam('userid');
        $this->view->storeall = Application_Model_StoreItem::byselsstore($id,$userid,$pagesize,$pageindex);
        $this->view->storelist = $this->view->storeall['list'];
        $this->view->id = $id;
        $this->_helper->layout->disableLayout();
    }
    public function userstoreAction()
    {
        $pagesize=5;        
        $pageindex = $this->getSafeParam('start');
        if(!$pageindex){$pageindex=0;}
        $id = $this->getSafeParam('id');
        $userid = $this->getSafeParam('userid');
        $this->view->storeall = Application_Model_StoreItem::bysurplusstore($id,$userid,$pagesize,$pageindex);
        $this->view->storelist = $this->view->storeall['list'];
        $this->view->id = $id;
        $this->_helper->layout->disableLayout();
    }
    
    public function billdetailAction()
    {
        $billNo = $this->getSafeParam("billNo");

        $result = Application_Model_wayBillItem::bybillNo($billNo);
        if($result){
            echo 1;
        }else{
            echo 2;
        }
        exit;
    }
    
    public function returngoodsAction() {
        $storeId = $this->getSafeParam('storeid');
        $userId = $this->getSafeParam('userid');
        $orderNo = $this->getSafeParam('orderno');
        $productName = $this->getSafeParam('productname');
        $readdres = $this->getSafeParam('readdres');
        $note = $this->getSafeParam('note');
        $op = new Application_Model_StoreItem($storeId);
        $op->state = Application_Model_StoreItem::STATUS_ReturnOf;
        $op->save();
        Application_Model_Operate::addOperate(0, null, $op->barcode, "包裹申请退货", $op->userid);
        $opt = new Application_Model_ReturnGoods();
        $opt->storeItemId = $storeId;
        $opt->userId = $userId;
        $opt->orderNo = $orderNo;
        $opt->returnNote = $note;
        $opt->productName = $productName;
        $opt->readdres = $readdres;
        $opt->state = 1;
        $opt->isDelete = 0;
        $opt->CkPass = 0;
        $opt->save();
        $this->redirect('regoodslist', 'Managestore');
    }
    
    public function editregoodsAction(){
        $id = $this->getSafeParam("id");
        $regoods = Application_Model_ReturnGoods::load($id);
        if($regoods){
            $this->json(array('type'=>1,'storeItemId'=>$regoods->storeItemId,
                'userId'=>$regoods->userId,'productName'=>$regoods->productName,
                'orderNo'=>$regoods->orderNo,'returnNote'=>$regoods->returnNote,
                'state'=>$regoods->state,'isDelete'=>$regoods->isDelete,
                'readdres'=>$regoods->readdres,'renumber'=>$regoods->renumber,
                'refreight'=>$regoods->refreight));
        }else{
            $this->json(array('type'=>2));
        }          
    }
    
    public function regoodsprocessAction(){
        $id = $this->getSafeParam("id");
        $note = $this->getSafeParam("note");
        $readdres = $this->getSafeParam('readdres');
        $renumber = $this->getSafeParam('renumber');
        $refreight = $this->getSafeParam('refreight');
        $regoods = Application_Model_ReturnGoods::load($id);
        $storeItem = Application_Model_StoreItem::load($regoods->storeItemId);
        $storeItem->state = Application_Model_StoreItem::STATUS_AchieveRe;
        $storeItem->save();
        Application_Model_Operate::addOperate(0, null, $storeItem->barcode, "包裹退货完成", $storeItem->userid);
        $regoods->state = 2;
        $regoods->returnNote = $note;
        $regoods->readdres = $readdres;
        $regoods->renumber = $renumber;
        $regoods->refreight = $refreight;
        $regoods->save();
        $this->redirect('regoodslist', 'Managestore');
    }
    
    public function isproblemAction()
    {
        $storeid = $this->getSafeParam("storeid");
        $examineType = $this->getSafeParam("examineType");
        $problemContent = $this->getSafeParam("problemContent");
        $isAbnormal = $this->getSafeParam("isAbnormal");
        $orderProblemImg = $this->getSafeParam("orderProblemImg");
        if($problemContent == ""){
            $this->json(array("status"=>2));
            return ;
        }
        $objectType = "";
        $objectItem = false;
        $isUnbind = false;
        if($examineType == "ingProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Ing;
            $objectItem = Application_Model_ingstore::load($storeid);
        } else if ($examineType == "rerProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Exchange;
            $objectItem = Application_Model_ReturnGoods::load($storeid);
        } else if ($examineType == "orderProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Order;
            $objectItem = Application_Model_Order::load($storeid);
            $objectItem->isAbnormal = $isAbnormal;
            if($isAbnormal == Application_Model_Order::Abnormal_Error){
//                $isUnbind = true;
//                Application_Model_Mail::addMail( "您收到一个质检异常的包裹",1,$objectItem->userId, "您的代购订单".$objectItem->OrderNum."入库出现质检异常，<a href='/member/orderdetail/id/".$objectItem->Id."' target='_block'>点击查看详情！</a>");
            }
        } else if ($examineType == "orderItemProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_OrderItem;
            $objectItem = Application_Model_OrderItem::load($storeid);
            if($isAbnormal == Application_Model_Order::Abnormal_Less){
                $objectItem->status = Application_Model_OrderItem::Status_Less;
            } else if ($isAbnormal == Application_Model_Order::Abnormal_Error){
                $objectItem->status = Application_Model_OrderItem::Status_Error;
                $objectItem->save();
            }
            $orderItem = Application_Model_Order::load($objectItem->OrderId);
            $orderItem->isAbnormal = $isAbnormal;
            $orderItem->save();
//            foreach ($orderItem->getItems() as $itemVal) {
//                $isUnbind = true;
//                if ($itemVal->status != Application_Model_Order::Abnormal_Error){
//                    $isUnbind = false;
//                }
//            }
        } else if ($examineType == "visitingProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Visiting;
            $objectItem = Application_Model_VisitingServer::load($storeid);
        } else if ($examineType == "visitingWayProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_VisitingWay;
            $objectItem = Application_Model_VisitingServer::load($storeid);
        } else if($examineType == "onlineProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Online;
            $objectItem = Application_Model_ingstore::load($storeid);


            if($isAbnormal == Application_Model_Order::Abnormal_Less){
                $objectItem->isAbnormal = Application_Model_ingstoreproduct::Insert_Less;
            } else if ($isAbnormal == Application_Model_Order::Abnormal_Error){
                $objectItem->isAbnormal = Application_Model_ingstoreproduct::Insert_Error;
                $objectItem->save();
            }
        } else if($examineType == "onlinesingProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Onlinesing;
            $objectItem = Application_Model_ingstoreproduct::load($storeid);

            if($isAbnormal == Application_Model_Order::Abnormal_Less){
                $objectItem->status = Application_Model_ingstoreproduct::Insert_Less;
            } else if ($isAbnormal == Application_Model_Order::Abnormal_Error){
                $objectItem->status = Application_Model_ingstoreproduct::Insert_Error;
                $objectItem->save();
            }
        }
        if($objectType == "" || !$objectItem){
            $this->json(array("status"=>0));
            return ;
        }
        $operator = Uuch_Util::getUserNikeName();
        $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($storeid,$objectType);
        if($problemItem){
            $problemId = $problemItem->Id;
        } else {
            $problemId = Application_Model_QualityProblem::addQualtiyProblem($objectType, $storeid);
        }
        $contentProblemId = Application_Model_QualityProblemContent::addQualityProblemContent($problemId, $problemContent, date("Y-m-d H:i:s"), $operator,  Application_Model_QualityProblemContent::Status_Default);
		$orderProblemImg = str_replace("http://www.uuch.com", "", $orderProblemImg);
        Application_Model_QualityProblemImg::addQualityProblemImg($contentProblemId, str_replace("http://old.uuch.com", "", $orderProblemImg));
        
        $objectItem->CkPass = Application_Model_DomainobjectType::CK_Problem;
        $objectItem->save();
        $this->json(array("status"=>1,"isUnbind" =>$isUnbind));
        return ;
    }
    public function problemcontentAction()
    {
        $storeid = $this->getSafeParam("storeid");
        $examineType = $this->getSafeParam("examineType");
        $objectType = "";
        $objectItem = false;
        if($examineType == "ingProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Ing;
            $objectItem = Application_Model_ingstore::load($storeid);
        } else if ($examineType == "rerProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Exchange;
            $objectItem = Application_Model_ReturnGoods::load($storeid);
        } else if ($examineType == "orderProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Order;
            $objectItem = Application_Model_Order::load($storeid);
        } else if ($examineType == "orderItemProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_OrderItem;
            $objectItem = Application_Model_OrderItem::load($storeid);
        } else if ($examineType == "visitingProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Visiting;
            $objectItem = Application_Model_VisitingServer::load($storeid);
        } else if ($examineType == "visitingWayProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_VisitingWay;
            $objectItem = Application_Model_VisitingServer::load($storeid);
        } else if($examineType == "onlineProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Online;
            $objectItem = Application_Model_ingstore::load($storeid);
        } else if($examineType == "onlinesingProblem"){
            $objectType = Application_Model_DomainobjectType::ObjectType_Onlinesing;
            $objectItem = Application_Model_ingstoreproduct::load($storeid);
        }
        if($objectType == "" || !$objectItem){
            $this->json(array("status"=>0));
            return ;
        }
        $problemItem = Application_Model_QualityProblem::byObjectIdObjectType($storeid,$objectType);
        $contentArr = $problemItem?$problemItem->getContentTrack():"";
        $problemNum = $problemItem?$problemItem->getNum(Application_Model_QualityProblemContent::Status_Default):0;
//        if($problemNum == 0){
//            $objectItem->CkPass = Application_Model_DomainobjectType::CK_Solve;
//            $objectItem->save();
//        }
        $this->json(array("status"=>1,"contentArr"=>$contentArr,"problemNum"=>$problemNum));
        
    }
    public function delproblemAction()
    {
        $contentId = $this->getSafeParam("contentId");
        $contentItem = Application_Model_QualityProblemContent::load($contentId);
        if(!$contentItem){
            $this->json(array("status"=>0));
            return ;
        }
        $problemId = $contentItem->ProblemId;
        $contentItem->delete();
        $problemNum = Application_Model_QualityProblemContent::getNum($problemId,"");
        if($problemNum == 0){
            $problemItem = Application_Model_QualityProblem::load($problemId);
            $problemItem->delProblem();
            $problemItem->delete();
        }
        $this->json(array("status"=>1));
        return ;
    }
    
    public function storelocationAction(){
        
        $this->setTitle("库位管理");
        $name = $this->getSafeParam("name");
        if($name != ""){
            $search = Application_Model_StoreLocation::getSearch($name);
            $this->view->search = $search;
        }
        $pos = array('aa','ab','ac','ad','ae','af','ag','ah','ai','aj','ak','al','am','an','ao','ap','aq','ar','as','at','au','av','aw','ax','ay','az', 'a2', 'a3');
        foreach ($pos as $key){
            $this->view->$key = Application_Model_StoreLocation::getAllLocation($key);
        }
        $this->view->pos = $pos;
        $this->view->type = 'store';
        $this->view->stype = 13;
    }

     /**
        历史库存
    */
    public function historylistAction(){
        $this->setTitle("历史库存");
        $stype = 5;
        $quick = $this->getSafeParam('quick');
        $pagesize = $this->getSafeParam('pagesize');
        $start = $this->getSafeParam('start'); 
        if(!$pagesize){ $pagesize=10; }
        if (!$start) {$start = 0;}
        $isdel = $this->getSafeParam("isdel");        
        if($quick == ""){            
            $history = $this->getSafeParam('history');                                   
            $intype = $this->getSafeParam('intype');
            $timescope = $this->getSafeParam('timescope');
            $starttime = $this->getSafeParam('starttime');
            $endtime = $this->getSafeParam('endtime');
            $strart = date("m")%3==0?date("m")/3:((int)(date("m")/3)+1);        
            $shiptype = $this->getSafeParam('shiptype');
            $interior = $this->getSafeParam('interior');
            $startWeight = $this->getSafeParam('startWeight');
            $endWeight = $this->getSafeParam('endWeight');
            $startVolume = $this->getSafeParam('startVolume');
            $endVolume = $this->getSafeParam('endVolume');
            $day = $this->getSafeParam('day');
            $stus = $this->getSafeParam('stus');
            $nostore = $this->getSafeParam('nostore');
            $notscan = $this->getSafeParam('notscan');
            $special = $this->getSafeParam('special');
            $personal = Application_Model_User::getByStoreNo($quick)?Application_Model_User::getByStoreNo($quick):"";
            $problem = $this->getSafeParam("problem");
            
            if($personal){
                $this->view->personalCount = Application_Model_StoreItem::personalCount($personal->id);
                $this->view->personalInCount = Application_Model_StoreItem::personalInCount($personal->id);
            }
            if($timescope != null){
                switch ($timescope) {
                    case "yesterday":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
                        break;
                    case "day3":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                    case 'lastweek':
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1-7,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+7-7,date("Y")));
                        break;
                    case "week":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+7,date("Y")));
                        break;
                    case "month":
                        $starttime =  date("Y-m-d",mktime(0,0,0,date("m"),1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("t"),date("Y")));
                        break;
                    case "lastmonth":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m")-1,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m")-1,cal_days_in_month(CAL_GREGORIAN, date("m")-1, date("Y")),date("Y")));
                        break;
                    case "quarter":
                        $starttime = date("Y-m-d",mktime(0,0,0,($strart-1)*3+1,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,$strart*3,cal_days_in_month(CAL_GREGORIAN, $strart*3, date("Y")),date("Y")));
                        break;
                    case "lastquarter":
                        $starttime = date("Y-m-d",mktime(0,0,0,($strart-1)*3-2,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,($strart-1)*3,cal_days_in_month(CAL_GREGORIAN, ($strart-1)*3, date("Y")),date("Y")));
                        break;
                    case "year":
                        $starttime = date("Y-m-d",mktime(0,0,0,1,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,12,cal_days_in_month(CAL_GREGORIAN, 12, date("Y")),date("Y")));
                        break;
                    case "lastyear":
                        $starttime = date("Y-m-d",mktime(0,0,0,1,1,date("Y")-1));
                        $endtime = date("Y-m-d",mktime(0,0,0,12,cal_days_in_month(CAL_GREGORIAN, 12, date("Y")-1),date("Y")-1));
                        break;
                    case "day7":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-6,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                    case "day30":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-30,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                    default :
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-90,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                }
            }else{
                if($starttime == null && $endtime == ""){
                    $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")-1));
                    $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                }
            }
            if($nostore){
                $quick = trim($nostore);
    //          $storeno = trim($nostore);
                $interior = Application_Model_StoreItem::Interior_InStored;
            }        
            if($stus != ''){
                if($stus == 1){
                    if($day == 1){
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                    }
                    $stype = 6;
                }else if($stus == 2){
                    if($day == 1){
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                    }
                    $stype = 7;
                }else if($stus == 0){
                    $interior = '';
                }else{
                    $interior = $this->getSafeParam('interior');
                }
            }                        
            if($special == "special"){
                $stype = 17;
            }
            if($problem == 1){
                $stype = 77;
            }
            $words = array();
            for($i=0;$i<26;$i++){
                $words[]= chr(65+$i);
            }
            if($notscan == "notscan"){
                $stype = 3;
            }else if($notscan == "beyondnotscan"){
                $stype = 100;
            }
            $this->view->words = $words?$words:"";            
            $this->view->starttime = $starttime;
            $this->view->endtime = $endtime;
            $this->view->shiptype = $shiptype;
            $this->view->interior = $interior;
            $this->view->intype = $intype;
            $this->view->pagesize = $pagesize;
            $this->view->startWeight = $startWeight;
            $this->view->endWeight = $endWeight;
            $this->view->startVolume = $startVolume;
            $this->view->endVolume = $endVolume;
            $this->view->notscan = $notscan;
            $this->view->timescope = $timescope;
            $this->view->personal = $personal;
            $this->view->special = $special;            
            $this->view->history = $history;
            
            $this->view->stus = $stus;
            $this->view->problem = $problem;
            if($history == "1"){
                $stype = 5;
            }else if($history == "2"){
                $stype = 4;
            }
        }
        $storeItemSearch = new Application_Model_Filter_StoreItemSearch();
        $storeItemSearch->quick = $quick?$quick:"";
        $storeItemSearch->isdel = $isdel?$isdel:"";
        if($quick == ""){
            $storeItemSearch->dateinbegin = $starttime?$starttime:"";
            $storeItemSearch->dateinend = $endtime?$endtime:"";
            $storeItemSearch->stus = $stus?$stus:"";
            $storeItemSearch->interior = $interior?$interior:"";
            $storeItemSearch->day = $day?$day:"";            
            $storeItemSearch->notscan = $notscan?$notscan:"";
            $storeItemSearch->intype = $intype?$intype:"";
            $storeItemSearch->startWeight = $startWeight?$startWeight:"";
            $storeItemSearch->endWeight = $endWeight?$endWeight:"";
            $storeItemSearch->startVolume = $startVolume?$startVolume:"";
            $storeItemSearch->endVolume = $endVolume?$endVolume:"";
            $storeItemSearch->shiptype = $shiptype?$shiptype:"";
            $storeItemSearch->special = $special?$special:"";
            $storeItemSearch->history = $history?$history:"";
            $storeItemSearch->problem = $problem?$problem:"";
        }
        if($isdel == 1){
            $stype = 8;
        }
        $this->view->isdel = $isdel;
        $this->view->quick = $quick;
        $this->view->StoreItem = Application_Model_StoreItem::getHistoryFilter($storeItemSearch,$pagesize,$start);
        $this->view->StoreItemList = $this->view->StoreItem['list']; 
        $this->view->interiorNames = Application_Model_StoreItem::getInteriorNames();
        $this->view->stype = $stype;        
    }

    
     /**
        过期和已删除的物品
     */
    public function deletelistAction(){
        
        $this->setTitle("过期|删除过期物品");
        $stype = 8;
        $quick = $this->getSafeParam('quick');
        $pagesize = $this->getSafeParam('pagesize');
        $start = $this->getSafeParam('start'); 
        if(!$pagesize){ $pagesize=25; }
        if (!$start) {$start = 0;}
        $isdel = $this->getSafeParam("isdel");        
        if($quick == ""){            
            $history = $this->getSafeParam('history');                                   
            $intype = $this->getSafeParam('intype');
            $timescope = $this->getSafeParam('timescope');
            $starttime = $this->getSafeParam('starttime');
            $endtime = $this->getSafeParam('endtime');
            $strart = date("m")%3==0?date("m")/3:((int)(date("m")/3)+1);        
            $shiptype = $this->getSafeParam('shiptype');
            $interior = $this->getSafeParam('interior');
            $startWeight = $this->getSafeParam('startWeight');
            $endWeight = $this->getSafeParam('endWeight');
            $startVolume = $this->getSafeParam('startVolume');
            $endVolume = $this->getSafeParam('endVolume');
            $day = $this->getSafeParam('day');
            $stus = $this->getSafeParam('stus');
            $nostore = $this->getSafeParam('nostore');
            $notscan = $this->getSafeParam('notscan');
            $special = $this->getSafeParam('special');
            $personal = Application_Model_User::getByStoreNo($quick)?Application_Model_User::getByStoreNo($quick):"";
            $problem = $this->getSafeParam("problem");
            
            if($personal){
                $this->view->personalCount = Application_Model_StoreItem::personalCount($personal->id);
                $this->view->personalInCount = Application_Model_StoreItem::personalInCount($personal->id);
            }
            if($timescope != null){
                switch ($timescope) {
                    case "yesterday":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
                        break;
                    case "day3":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                    case 'lastweek':
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1-7,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+7-7,date("Y")));
                        break;
                    case "week":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+7,date("Y")));
                        break;
                    case "month":
                        $starttime =  date("Y-m-d",mktime(0,0,0,date("m"),1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("t"),date("Y")));
                        break;
                    case "lastmonth":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m")-1,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m")-1,cal_days_in_month(CAL_GREGORIAN, date("m")-1, date("Y")),date("Y")));
                        break;
                    case "quarter":
                        $starttime = date("Y-m-d",mktime(0,0,0,($strart-1)*3+1,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,$strart*3,cal_days_in_month(CAL_GREGORIAN, $strart*3, date("Y")),date("Y")));
                        break;
                    case "lastquarter":
                        $starttime = date("Y-m-d",mktime(0,0,0,($strart-1)*3-2,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,($strart-1)*3,cal_days_in_month(CAL_GREGORIAN, ($strart-1)*3, date("Y")),date("Y")));
                        break;
                    case "year":
                        $starttime = date("Y-m-d",mktime(0,0,0,1,1,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,12,cal_days_in_month(CAL_GREGORIAN, 12, date("Y")),date("Y")));
                        break;
                    case "lastyear":
                        $starttime = date("Y-m-d",mktime(0,0,0,1,1,date("Y")-1));
                        $endtime = date("Y-m-d",mktime(0,0,0,12,cal_days_in_month(CAL_GREGORIAN, 12, date("Y")-1),date("Y")-1));
                        break;
                    case "day7":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-6,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                    case "day30":
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-30,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                    default :
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-90,date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        break;
                }
            }else{
                if($starttime == null && $endtime == ""){
                    $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")-1));
                    $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                }
            }
            if($nostore){
                $quick = trim($nostore);
    //          $storeno = trim($nostore);
                $interior = Application_Model_StoreItem::Interior_InStored;
            }        
            if($stus != ''){
                if($stus == 1){
                    if($day == 1){
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                    }
                    $stype = 6;
                }else if($stus == 2){
                    if($day == 1){
                        $starttime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                        $endtime = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
                    }
                    $stype = 7;
                }else if($stus == 0){
                    $interior = '';
                }else{
                    $interior = $this->getSafeParam('interior');
                }
            }                        
            if($special == "special"){
                $stype = 17;
            }
            if($problem == 1){
                $stype = 77;
            }
            $words = array();
            for($i=0;$i<26;$i++){
                $words[]= chr(65+$i);
            }
            if($notscan == "notscan"){
                $stype = 3;
            }else if($notscan == "beyondnotscan"){
                $stype = 100;
            }
            $this->view->words = $words?$words:"";            
            $this->view->starttime = $starttime;
            $this->view->endtime = $endtime;
            $this->view->shiptype = $shiptype;
            $this->view->interior = $interior;
            $this->view->intype = $intype;
            $this->view->pagesize = $pagesize;
            $this->view->startWeight = $startWeight;
            $this->view->endWeight = $endWeight;
            $this->view->startVolume = $startVolume;
            $this->view->endVolume = $endVolume;
            $this->view->notscan = $notscan;
            $this->view->timescope = $timescope;
            $this->view->personal = $personal;
            $this->view->special = $special;            
            $this->view->history = $history;
            
            $this->view->stus = $stus;
            $this->view->problem = $problem;
            if($history == "1"){
                $stype = 5;
            }else if($history == "2"){
                $stype = 4;
            }
        }
        $storeItemSearch = new Application_Model_Filter_StoreItemSearch();
        $storeItemSearch->quick = $quick?$quick:"";
        $storeItemSearch->isdel = $isdel?$isdel:"";
        if($quick == ""){
            $storeItemSearch->dateinbegin = $starttime?$starttime:"";
            $storeItemSearch->dateinend = $endtime?$endtime:"";
            $storeItemSearch->stus = $stus?$stus:"";
            $storeItemSearch->interior = $interior?$interior:"";
            $storeItemSearch->day = $day?$day:"";            
            $storeItemSearch->notscan = $notscan?$notscan:"";
            $storeItemSearch->intype = $intype?$intype:"";
            $storeItemSearch->startWeight = $startWeight?$startWeight:"";
            $storeItemSearch->endWeight = $endWeight?$endWeight:"";
            $storeItemSearch->startVolume = $startVolume?$startVolume:"";
            $storeItemSearch->endVolume = $endVolume?$endVolume:"";
            $storeItemSearch->shiptype = $shiptype?$shiptype:"";
            $storeItemSearch->special = $special?$special:"";
            $storeItemSearch->history = $history?$history:"";
            $storeItemSearch->problem = $problem?$problem:"";
            
        }
        if($isdel == 1){
            $stype = 8;
        }
        $this->view->isdel = $isdel;
        $this->view->quick = $quick;
        $this->view->StoreItem = Application_Model_StoreItem::getMydeleteByFilter($storeItemSearch,$pagesize,$start);
        $this->view->StoreItemList = $this->view->StoreItem['list']; 
        $this->view->interiorNames = Application_Model_StoreItem::getInteriorNames();
        $this->view->stype = $stype;      
    }

    /**
      打印过期删除物品清单
    */

    public function printdeletelistAction(){
        $this->setTitle("打印|删除过期物品");
        $id = $this->getSafeParam('id');
        $this->view->StoreItem = Application_Model_StoreItem::getPrintdeletelist($id);
        $this->view->StoreItemList = $this->view->StoreItem; 
    }

    /**
      扫描过期物品，清除库位
    */
    public function pdadelcheckAction(){
        $this->setTitle("扫描|pad扫描出库");
        $this->_helper->layout->disableLayout();
    }
    /**
      扫描过期物品，验证是否正确
    */
    public function checkbarcodeAction(){
        $barcode = $_GET['barcode'];
        $type = Application_Model_StoreItem::getcheckbarcode($barcode);
        $this->json(array('type' =>$type));
    }

       /**
      批量出库，验证是否正确
    */
    public function checkbatchAction(){
        $idlist = $this->getSafeParam('idlist');
        $type = Application_Model_StoreItem::getcheckbath($idlist);
        $this->json(array('type' =>$type));
    }

    public function bindinglocationAction(){
        $this->view->type = 'store';
        $this->view->stype = 2;
    }
    
    public function bindingAction(){         
        $locationNo = $this->getSafeParam("locationNo");
        $barcode = $this->getSafeParam("barcode");         
        $storeItem = Application_Model_StoreItem::surebybarcode($barcode);     
        $opt = new Application_Model_StoreLocation();
        $one = $opt->queryOne(array('locationNo'=>$locationNo,'status'=>0));               
        $storelocation = Application_Model_StoreLocation::load($one->id);
        if($storeItem && $one){
            $storelocation->userId = $storeItem->userid;
            $storelocation->status = 1;
            $storelocation->save();
            $this->json(1);
        }else{
            $this->json(0);
        }
    }
    
    public function storageAction(){
        //$this->view->type = 'storelocation';
        $this->view->stype = 2;
        $this->_helper->layout->disableLayout();
    }
    
    /**
     * 入库扫描
     */
    public function instorageAction(){
        error_reporting(NULL);
        ini_set('display_errors','Off');
        $locationNo = $this->getSafeParam("locationNo");
        $barcode = $this->getSafeParam("barcode");
        $storeItem = Application_Model_StoreItem::surebybarcode($barcode);
        $opt = new Application_Model_StoreLocation();
        $opt->emptyLocation($locationNo);
        $one = $opt->queryOne(array('locationNo'=>$locationNo,'status'=>1));
        $store = new Application_Model_StoreItem();
        if($locationNo != "GZ-11" && $locationNo != "BH-11" && $locationNo != "GQ-11" && $locationNo != "TS-11" && $locationNo != "WT-11" && !preg_match('{^DH-}', $locationNo)){
            if($one){
                if($storeItem){
                    if($storeItem->userid == $one->userId){
                        $op = Application_Model_StoreItem::load($storeItem->id);
                        $op->locationNo = $locationNo;
                        $storeNo = $opt->getLocation($storeItem->userid);
                        Application_Model_Operate::addOperate(0, null, $storeItem->barcode, "包裹扫描入库", $storeItem->userid);
                        if($storeItem->State == Application_Model_StoreItem::STATUS_Sended){
                            $op->save();
                            $this->json(array('type'=>8,'nikename'=>$storeItem->userinfo->nikename,'sno'=>$storeItem->userinfo->storeno,'storeNo'=>$storeNo));  //该包裹与该用户相对应(已经出库的包裹重新扫描)
                        }else{
                            $op->interior = Application_Model_StoreItem::Interior_InStored;
                            $op->save();                        
                            $this->json(array('type'=>1,'nikename'=>$storeItem->userinfo->nikename,'sno'=>$storeItem->userinfo->storeno,'storeNo'=>$storeNo));  //该包裹与该用户相对应
                        }                        
                    }else{
                        $count = $store->isNullLocation($one->userId);
                        if($count > 0 && $one->userId != $storeItem->userid){                        
                            $storeNo = $opt->getLocation($storeItem->userid);
                            $this->json(array('type'=>5,'sno'=>$one->userinfo->storeno,'nikename'=>$one->userinfo->nikename,'storeNo'=>$storeNo));     //报错 该库位已经被别的用户占用 
                        }else{
                            $one = $opt->queryOne(array('locationNo'=>$locationNo));
                            $opt1 = Application_Model_StoreLocation::load($one->id);
                            $opt1->userId = $storeItem->userid;
                            $opt1->datecreated = date("Y-m-d H:i:s");
                            $opt1->save();
                            $storeNo = $opt->getLocation($storeItem->userid);
                            $op = Application_Model_StoreItem::load($storeItem->id);
                            $op->locationNo = $locationNo;
                            Application_Model_Operate::addOperate(0, null, $storeItem->barcode, "包裹扫描入库", $storeItem->userid);
                            if($storeItem->State == Application_Model_StoreItem::STATUS_Sended){
                                $op->save();
                                $this->json(array('type'=>9,'sno'=>$storeItem->userinfo->storeno,'nikename'=>$storeItem->userinfo->nikename,'storeNo'=>$storeNo));   //该用户绑定该库位(已经出库的包裹重新扫描)
                            }else{
                                $op->interior = Application_Model_StoreItem::Interior_InStored;
                                $op->save();                        
                                $this->json(array('type'=>2,'sno'=>$storeItem->userinfo->storeno,'nikename'=>$storeItem->userinfo->nikename,'storeNo'=>$storeNo));   //该用户绑定该库位
                            }                            
                        }
                    }                
                }else{
                    $this->json(array('type'=>3));      //不存在该包裹   
                }
            }else{
                $one2 = $opt->queryOne(array('locationNo'=>$locationNo,'status'=>0));
                if($one2){           
                    $storelocation = Application_Model_StoreLocation::load($one2->id);
                    if($storeItem){
                        $storelocation->userId = $storeItem->userid;
                        $storelocation->datecreated = date("Y-m-d H:i:s");
                        $storelocation->status = 1;
                        $storelocation->save();
                        $storeNo = $opt->getLocation($storeItem->userid);
                        $op = Application_Model_StoreItem::load($storeItem->id);
                        $op->locationNo = $locationNo;
                        Application_Model_Operate::addOperate(0, null, $storeItem->barcode, "包裹扫描入库", $storeItem->userid);
                        if($storeItem->state == Application_Model_StoreItem::STATUS_Sended){
                            $op->save();                    
                            $this->json(array('type'=>10,'nikename'=>$storeItem->userinfo->nikename,'sno'=>$storeItem->userinfo->storeno,'storeNo'=>$storeNo));    //该库位号是空的,并且该用户成功绑定该库位(已经出库的包裹重新扫描)
                        }else{
                            $op->interior = Application_Model_StoreItem::Interior_InStored;
                            $op->save();                            
                            $this->json(array('type'=>6,'nikename'=>$storeItem->userinfo->nikename,'sno'=>$storeItem->userinfo->storeno,'storeNo'=>$storeNo));    //该库位号是空的,并且该用户成功绑定该库位
                        }
                    }else{
                        $this->json(array('type'=>7));         //该库位是空，但是该用户绑定该库位失败
                    }                                
                }else{
                    $this->json(array('type'=>4));   //该库位不存在
                }            
            }
        }else{
            $specialLocation = new Application_Model_StoreLocation();
            $specialLocation->queryOne(array('locationNo'=>$locationNo));
            if($specialLocation){
                if($storeItem){
                    $op = Application_Model_StoreItem::load($storeItem->id);
                    $op->locationNo = $locationNo;
                    $op->interior = Application_Model_StoreItem::Interior_InStored;
                    $op->save();
                    Application_Model_Operate::addOperate(0, null, $storeItem->barcode, "包裹扫描入库", $storeItem->userid);
                    $this->json(array('type'=>11,'nikename'=>$storeItem->userinfo->nikename,'sno'=>$storeItem->userinfo->storeno,'storeNo'=>$storeNo));  //该包裹存放在特殊库位                    
                }else{
                    $this->json(array('type'=>3));      //不存在该包裹   
                } 
            }else{
                $this->json(array('type'=>4));   //该库位不存在
            }
        }
    }
            
    public function relocationAction()
    {
        $this->view->type = 'store';
        $this->view->stype = 14;
    }
    
    public function locationinfoAction()
    {
        $locationNo = $this->getSafeParam("locationNo");
        $result = Application_Model_StoreLocation::getLocationInfo($locationNo);
        if($result){
            $this->json(array("status"=>$result->status,"username"=>$result->userinfo->nikename,"storeno"=>$result->userinfo->storeno));
        }else{
            $this->json(0);
        }
    }
    public function removelocationAction()
    {
        $locationNo = $this->getSafeParam("locationNo");
        $result = Application_Model_StoreLocation::getRemoveLocation($locationNo);
        $this->json($result);
    }
    
    public function printprocessAction(){
        $storeNo = $this->getSafeParam("storeNo");
        $user = Application_Model_User::getByStoreNo($storeNo);
        if($user){
            $this->json(array('type'=>1,'storeNo'=>$storeNo,'nikeName'=>$user->nikename));
        }else{
            $this->json(array('type'=>2));
        }
    }
    
    public function generatebarcodeAction(){
        $barcode = date("ymd") . substr(time(), -5, 5);
        $mycount = Application_Model_StoreItem::isSetBarcode($barcode);
        if($mycount == 0){
            $this->json(array('type'=>1,'barcode'=>$barcode));
        }else{
            $this->json(array('type'=>2,'barcode'=>$barcode));
        }
    }

    public function delstoreitembyidAction(){
        $id = $this->getSafeParam("id");
        $storeitem = Application_Model_StoreItem::load($id);        
        if($storeitem->state != Application_Model_StoreItem::STATUS_Sended){
            $storeitem->isdelete = 1;
            $storeitem->state = Application_Model_StoreItem::STATUS_InStored;
            $storeitem->operatedate=date('Y-m-d H:i:s');
            $storeitem->operate=1;
            $storeitem->save();
            if($storeitem->waybillinfo){
                $wayItem = Application_Model_WayItem::getWayIdStoreIdByStatus($storeitem->waybillinfo->Id, $id);
                $wayItem->delete();
            }
            Application_Model_Operate::addOperate(0, null, $storeitem->barcode, "删除包裹", $storeitem->userid);
            $this->json(array('type'=>1));
        }else{
            $this->json(array('type'=>2));
        }
    }
    
    public function topaypackageAction(){
        $this->view->stype = 18;
        $quick = $this->getSafeParam("quick");
        $start = $this->getSafeParam("start")?$this->getSafeParam("start"):0;
        $count = $this->getSafeParam("count")?$this->getSafeParam("count"):20;
        $dateinbegin = $this->getSafeParam("dateinbegin");
        $dateinend = $this->getSafeParam("dateinend");
        $this->view->quick = $quick;
        $this->view->start = $start;
        $this->view->count = $count;
        $this->view->dateinbegin = $dateinbegin;
        $this->view->dateinend = $dateinend;
        $storeItemSearch = new Application_Model_Filter_StoreItemSearch();
        $storeItemSearch->quick = $quick;
        $storeItemSearch->isShipFee = 1;
        $storeItemSearch->dateinbegin = $dateinbegin;
        $storeItemSearch->dateinend = $dateinend;
        $this->view->storeAll = Application_Model_StoreItem::getMyByFilter($storeItemSearch, $count, $start);
        $this->view->StoreItemList = $this->view->storeAll['list'];    
    }
    
    public function disposeproblemAction()
    {
        $id = $this->getSafeParam("id");
        $storeItem = Application_Model_StoreItem::load($id);
        if($storeItem && $storeItem->IsProblem == 1){
            $storeItem->IsProblem = 0;
            $storeItem->save();
            Application_Model_Operate::addOperate(0, null, $storeItem->barcode, "处理问题包裹", $storeItem->userid);
            $this->json(1);
        }else{
            $this->json(0);
        }
    }
    
    /**
     * 换货  -- 入库验货
     */
    public function inspectionAction(){
        $logistics = $this->getSafeParam("logistics");
        $item = Application_Model_ReturnGoods::getByLogistics($logistics);
        if($item){
            $item->Status = Application_Model_ReturnGoods::STATUS_Succeed;
            $storeItem = Application_Model_StoreItem::surebybarcode($item->storeinfo->barcode);            
            $storeItem->State = Application_Model_StoreItem::STATUS_AchieveExchange;
            $storeItem->Interior = Application_Model_StoreItem::Interior_AchieveExchange;
            $storeItem->Isdelete = 1;
            $storeItem->save();
            $item->save();
            $this->json(1);            
        }else{
            $this->json(0);
        }
        
    }
    
    /**
     * 换货  -- 入库出现问题
     */
    public function abnormalAction(){
        $logistics = $this->getSafeParam("logistics");
        $problemcontent = $this->getSafeParam("problemcontent");
        $item = Application_Model_ReturnGoods::getByLogistics($logistics);
        if($item){
            $item->problem = Application_Model_ReturnGoods::STATUS_Exception;
            $item->Exception = $problemcontent;
            $item->save();
            $this->json(1);
        }else{
            $this->json(0);
        }        
    }
    
    
    /**
     * 每天定时释放库位
     */
   public function releaselocationAction(){
        $location = new Application_Model_DbTable_StoreLocation();
        $location->releaseLocation();
        exit();
   } 
    
   public function cultvisitingAction() {
       $visitingId = $this->getSafeParam("visitingId");
       $visitingWeight = $this->getSafeParam("visitingWeight");
       $visitingVolumeWeight = $this->getSafeParam("visitingVolumeWeight");
       $visitingItem = Application_Model_VisitingServer::load($visitingId);
       if(!$visitingItem) {
           $this->json(array("type"=>0));
           return ;
       }
       $weight = $visitingWeight>=$visitingVolumeWeight?$visitingWeight:$visitingVolumeWeight;
       $prices = Application_Model_ExpressPrice::getPricesByCity($visitingItem->inlandTownId);
       $report = 0;
       foreach ($prices as $value) {
           if($value->ExpressId == $visitingItem->inlandShipType) {
            $report = $value->getReportMoney(($weight*1000));
            break;
           }
       }
       $report += 20; 
       $this->json(array("type"=>1,"shipFee"=>number_format($report,2)));
   }
       
}
